﻿using MySpace.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Member : System.Web.UI.Page
{
    protected static string type = "0";
    protected static string myear = DateTime.Now.Year.ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["type"]))
        {
            type = Request.QueryString["type"].ToString();
        }
        else
        {

        }
        if (!string.IsNullOrEmpty(Request.QueryString["myear"]))
        {
            myear = Request.QueryString["myear"].ToString();
        }
        else
        {
            myear = DateTime.Now.Year.ToString();
        }
        if (!IsPostBack)
        {
            this.DataBd();
            this.YearListBd();
            string t_title = myear + "届" + (type == "0" ? "干部" : (type == "1" ? "干事" : "社员"));
            theclass.Text += t_title;
            yeartitle.Text = t_title;
            Master.WebSubTitle += t_title+"-";
        }
    }
    private string getInittype()
    {
        return "";
    }
    private string getInityear()
    {
        return "";
    }
    protected void DataBd()
    {
        string sql = "";
        int t = Convert.ToInt16(type);
        if (t == 2)
        {
            sql = string.Format("select * from member where m_type={0} and m_rx_year='{1}' order by m_class desc", type, myear);
        }
        else
        {
            sql = string.Format("select * from member where m_type={0} and m_rz_year='{1}' order by id asc", type, myear);
        }
        DBHandler dbh = GetHandler.Init();
        dbh.CommandText = sql;
        feed_repeater.DataSource = dbh.ExecuteDataTable();
        feed_repeater.DataBind();
    }
    protected void YearListBd()
    {
        string sql = "";
        int t = Convert.ToInt16(type);
        if(t==2)
        {
            sql =string.Format( "select distinct m_rx_year as myear from member where m_type={0}" , type);
        }
        else
        {
            sql = string.Format("select distinct m_rz_year as myear from member where m_type={0}", type);
        }
        DBHandler dbh = GetHandler.Init();
        dbh.CommandText = string.Format(sql);
        DataTable indt = dbh.ExecuteDataTable();
        DataTable dt = new DataTable();
        dt.Columns.Add("lyear");//年份列表
        dt.Columns.Add("curyear");//当前年份
        dt.Columns.Add("inyear");//包含年份
        int y = DateTime.Now.Year;
        for (int i = y;i>= 1997;i--)
        {
            DataRow dr = dt.NewRow();
            dr["lyear"] = i.ToString() ;
            dr["curyear"] = Convert.ToInt32(myear) == i ? 1 : 0;
            foreach (DataRow r in indt.Rows)
            {
                if(r["myear"].ToString()==i.ToString())
                {
                    dr["inyear"] = 1;
                    break;
                }
                dr["inyear"] = 0;
            }
            dt.Rows.Add(dr);
        }
        rp_yearlist.DataSource=  dt;
        rp_yearlist.DataBind();
    }
}